package com.horay.springclouddemo.consumer.member.controller;

import com.horay.springclouddemo.common.http.ResultBody;
import com.horay.springclouddemo.consumer.member.client.MemberFeignClient;
import com.horay.springclouddemo.model.member.Member;
import com.horay.springclouddemo.model.member.MemberDTO;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 成员控制器
 *
 * @author heyingcheng
 * @date 2020/3/21 13:52
 */
@RestController
@RequestMapping("consumer/member")
public class MemberController {

    private final MemberFeignClient memberFeignClient;

    public MemberController(MemberFeignClient memberFeignClient) {
        this.memberFeignClient = memberFeignClient;
    }

    @PostMapping
    public ResponseEntity<ResultBody> createMember(@RequestBody Member member) {
        return memberFeignClient.createMember(member);
    }

    @GetMapping("{id}")
    public ResponseEntity<ResultBody> getMember(@PathVariable Integer id) {
        return memberFeignClient.getMember(id);
    }

    @GetMapping("members")
    public ResponseEntity<ResultBody> getMembers(@RequestBody MemberDTO memberDTO) {
        return memberFeignClient.getMembers(memberDTO);
    }

    @PutMapping
    public ResponseEntity<ResultBody> updateMember(Member member) {
        return memberFeignClient.updateMember(member);
    }

    @DeleteMapping("{id}")
    public ResponseEntity<ResultBody> deleteMember(@PathVariable Integer id) {
        return memberFeignClient.deleteMember(id);
    }

}
